home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Telephone Manager / Stiletto Sources / Sources / About.c next >
Encoding:
C/C++ Source or Header  |  1995-07-04  |  5.3 KB  |  208 lines  |  [TEXT/MPS ]

  1. /************************************************************************************************/
  2. /*                                                                                                */
  3. /*    Program Name:    Stiletto                                                                    */
  4. /*                                                                                                */
  5. /*    File Name:        About.c                                                                        */
  6. /*                                                                                                */
  7. /*    © Apple Computer, Inc. 1991-1995                                                            */
  8. /*    All Rights Reserved                                                                            */
  9. /*                                                                                                */
  10. /*    Revision History:                                                                            */
  11. /*                                                                                                */
  12. /*        Date        Who                    Modification                                            */
  13. /*                                                                                                */
  14. /*        1991-06-30    Chris Halim            Original version                                        */
  15. /*        1995-06-26    Jaakko Railo        Version 2.0                                                */
  16. /*                                                                                                */
  17. /************************************************************************************************/
  18.  
  19. /****************************************** DESCRIPTION ******************************************
  20.  
  21. *************************************************************************************************/
  22.  
  23. /******************************************** HEADERS *******************************************/
  24.  
  25. #include "Desk.h"
  26. #include "Fonts.h"
  27. #include "Resources.h"
  28. #include "ToolUtils.h"
  29.  
  30. #include "About.h"
  31. #include "Constants.h"
  32. #include "Utilities.h"
  33.  
  34. /****************************************** DEFINITIONS *****************************************/
  35.  
  36. #define MAXLONG        0x7FFFFFFF
  37.  
  38. /****************************************** PROTOTYPES ******************************************/
  39.  
  40. PicHandle         GetCenteredPict (short resID, const Rect * bounds, Rect * picFrame);
  41. void            DoSomething (DialogPtr theDialog);
  42.  
  43. /******************************************** GLOBALS *******************************************/
  44.  
  45. extern    ModalFilterUPP    gAboutFilterUPP;
  46. extern    UserItemUPP        gDrawAboutPictUPP;
  47. extern    UserItemUPP        gDrawVersUPP;
  48.  
  49. /************************************************************************************************/
  50. /************************************************************************************************/
  51.  
  52.  
  53. #pragma segment About
  54. PicHandle GetCenteredPict (short resID, const Rect * bounds, Rect * picFrame)
  55. {
  56.     PicHandle thePicture = GetPicture (resID);
  57.     
  58.     picFrame->top = (**thePicture).picFrame.top;
  59.     picFrame->left = (**thePicture).picFrame.left;
  60.     picFrame->right = (**thePicture).picFrame.right;
  61.     picFrame->bottom = (**thePicture).picFrame.bottom;
  62.     
  63.     OffsetRect(picFrame, -picFrame->left, -picFrame->top);
  64.     
  65.     OffsetRect(picFrame, (bounds->right-bounds->left-picFrame->right) / 2,
  66.          (bounds->bottom-bounds->top-picFrame->bottom) / 2);
  67.     
  68.     return (thePicture);
  69. }
  70.  
  71.  
  72. #pragma segment About
  73. pascal void DrawVers (DialogPtr theDialog, short itemNumber)
  74. {
  75.     short        itemKind;
  76.     Handle        itemHand;
  77.     Rect        itemRect;
  78.     VersRecHndl version;
  79.     
  80.     version = (VersRecHndl) GetResource ('vers', 1);
  81.     
  82.     GetDItem(theDialog, itemNumber, &itemKind, &itemHand, &itemRect);
  83.     
  84.     MoveTo (itemRect.left, itemRect.bottom);
  85.     TextSize (9);
  86.     TextFont (applFont);
  87.     DrawString ((**version).shortVersion);
  88.     
  89.     ReleaseResource ((Handle) version);
  90. }
  91.  
  92.  
  93. #pragma segment About
  94. pascal void DrawAboutPict (DialogPtr theDialog, short itemNumber)
  95. {
  96. #pragma    unused (itemNumber)
  97.  
  98.     Rect         picFrame;
  99.     PicHandle     aboutPic;    
  100.     
  101.     aboutPic = GetCenteredPict (rAboutPICT, &theDialog->portRect, &picFrame);
  102.     
  103.     DrawPicture(aboutPic, &picFrame);
  104.     
  105.     ReleaseResource ((Handle) aboutPic);
  106. }
  107.  
  108.  
  109. #pragma segment About
  110. void    DoSomething (DialogPtr theDialog)
  111. {
  112.     EventRecord    theEvent;
  113.     Boolean        gotEvent = false;
  114.     
  115.     PaintRect (&theDialog->portRect);
  116.     
  117.     while (!gotEvent)
  118.     {
  119.         gotEvent = WaitNextEvent (mDownMask + keyDownMask, &theEvent, MAXLONG, nil);
  120.     }
  121.     
  122.     EraseRect (&theDialog->portRect);
  123.     InvalRect (&theDialog->portRect);
  124. }
  125.  
  126.  
  127. #pragma segment About
  128. pascal Boolean AboutFilterProc (DialogPtr theDialog, EventRecord * theEvent, short * itemHit)
  129. {
  130.     Boolean            wasHandled = false;
  131.     char            key;
  132.     WindowPtr        theWindow;
  133.     static short    index = 0;
  134.     char            *code = "chris";
  135.             
  136.     switch (theEvent->what) {
  137.         case keyDown :
  138.             key = theEvent->message & charCodeMask;
  139.             
  140.             if (key == code[index]) {
  141.                 index++;
  142.                 if (index == 5) {
  143.                     DoSomething (theDialog);
  144.                     index = 0;
  145.                 }
  146.             }
  147.             else
  148.                 index = 0;
  149.             
  150.             switch (key) {
  151.                 case crKey :
  152.                 case enterKey :
  153.                     *itemHit = kHitItem;
  154.                     wasHandled = true;
  155.                     break;
  156.             }
  157.             break;             
  158.  
  159.         case mouseDown :
  160.             switch (FindWindow(theEvent->where, &theWindow)) {
  161.                 case inDrag:
  162.                     DragWindow(theWindow, theEvent->where, &qd.screenBits.bounds);
  163.                     wasHandled = true;
  164.                     break;
  165.                 case inSysWindow:
  166.                     SystemClick(theEvent, theWindow);
  167.                     wasHandled = true;
  168.                     break;
  169.                 case inGoAway:
  170.                     if ( TrackGoAway(theWindow, theEvent->where) )
  171.                         HideWindow (theWindow);
  172.                     wasHandled = true;
  173.                     break;
  174.             }
  175.             break;
  176.     }
  177.  
  178.     return (wasHandled);
  179. }
  180.  
  181. #pragma segment About
  182. void DoAbout (void)
  183. {
  184.     DialogPtr        theDialog;
  185.     short             itemType;
  186.     Handle            item;
  187.     Rect            box;
  188.     short            itemHit;
  189.     
  190.     theDialog = GetNewDialog (rAboutDLOG, nil, (WindowPtr) (-1L));
  191.     if (theDialog != nil) {
  192.         SetPort (theDialog);
  193.     
  194.         GetDItem(theDialog, kPictItem, &itemType, &item, &box);
  195.         SetDItem(theDialog, kPictItem, itemType, (Handle) gDrawAboutPictUPP, &box);
  196.     
  197.         GetDItem(theDialog, kVersItem, &itemType, &item, &box);
  198.         SetDItem(theDialog, kVersItem, itemType, (Handle) gDrawVersUPP, &box);
  199.         
  200.         ShowWindow (theDialog);
  201.         
  202.         do
  203.             ModalDialog (gAboutFilterUPP, &itemHit);
  204.         while (itemHit != kHitItem);
  205.  
  206.         DisposeDialog (theDialog);
  207.     }
  208. }